﻿
@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager
@inject IPageModelCatche<List<DiscountGameItemModel>> _pageModelCatche
<CnGalWebSite.Components.Containers.MiniModeContainer>
<section class="discount-games-card">
    <CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.SlideGroup Title="折扣中的游戏" Items="_items.Take(_dataCacheService.IsApp?9:16)" MoreLink="/discount">
            <MDCard Class="item" Href="@context.Url">
                <img src="@context.Image" alt="@context.Name" loading="lazy" />
                <div class="content">
                    <div class="name text-truncate-1 title-large">@context.Name</div>
                    <div class="brief text-truncate-3 label-large">@context.BriefIntroduction</div>
                    <div class="tags">
                        <CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.IconChip Color="success" Icon="IconType.Discount" Text="@($"{context.Cut}% OFF")" />
                        <CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.IconChip Color="info" Text="@($"¥ {context.Price:0.00}")" />
                    </div>
                </div>

            </MDCard>

    </CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.SlideGroup>
</section>
</CnGalWebSite.Components.Containers.MiniModeContainer>
@code {

    List<DiscountGameItemModel> _items { get; set; } = new List<DiscountGameItemModel>();

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    protected override async Task OnInitializedAsync()
    {
        try
        {
            _items = await _pageModelCatche.GetCache("api/home/ListDiscountGames");
            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取主页折扣游戏列表失败");
        }
    }
}
